/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Alert2.java
 *
 * Created on 17.6.2011, 19:40:17
 */
package forms;

import java.util.Iterator;
import src.Evidence;
import src.Krouzek;
import src.Zak;

/**
 *
 * @author Viktor
 */
public class Alert2 extends javax.swing.JFrame {
Evidence e;
boolean fired;
Krouzek k;
boolean prichozi;
Object[] listdata;
int pocet ;
    /** Creates new form Alert2 */
    public Alert2(boolean fired, Evidence e, Krouzek k, boolean prichozi) {
        initComponents();
        this.fired = fired;
        this.e = e;
        this.k = k;
        pocet = 0;
        fired = true;
        this.prichozi = prichozi;
        listdata = new Object[30];
        najdiLidi();
        vypisLidi();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        Seznam = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        nazevKr = new javax.swing.JLabel();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setText("<No init>");

        Seznam.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(Seznam);

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        nazevKr.setFont(new java.awt.Font("Tahoma", 1, 14));
        nazevKr.setText("<no init>");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(196, 196, 196)
                .addComponent(jLabel1)
                .addContainerGap(197, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(223, 223, 223)
                .addComponent(nazevKr)
                .addContainerGap(225, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(241, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(209, 209, 209))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(nazevKr)
                .addGap(13, 13, 13)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        k.setZobrazen(false);
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void najdiLidi() {
         for (Iterator it = e.getZaci().iterator(); it.hasNext();) {
            
            
            Zak z = (Zak)it.next();
            for (Iterator it1 = z.getKrouzky().iterator(); it1.hasNext();) {
                Krouzek kv =(Krouzek) it1.next();
                
                if(kv.equals(k)){
                String s = z.getPrijmeni() + ", " + z.getJmeno() + "    (" + z.getDatNar() + ")"; 
                    listdata[pocet] = s;
                    pocet++;
                    break;
                }
                         
                
            }
            
            
        }
    }

    /**
     * @param args the command line arguments
     */
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList Seznam;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel nazevKr;
    // End of variables declaration//GEN-END:variables

    private void vypisLidi() {
        if(prichozi){
            jLabel1.setText("Začíná kroužek");
            nazevKr.setText(k.getNazev());
        }else{
          jLabel1.setText("Skončil kroužek");
            nazevKr.setText(k.getNazev());   
        }
        Seznam.setListData(listdata);
    }
}
